@extends('layouts.admin')
@section('content')
    <div class="card">
        <div class="card-body">
            <ul class="nav nav-tabs nav-overflow header-tabs">
                <li class="nav-item">
                    <a href="{{route('admin.catergory.index')}}" class="nav-link pb-3 active">
                        栏目列表
                    </a>
                </li>
                <li class="nav-item">
                    <a href="{{route('admin.catergory.create')}}" class="nav-link pb-3">
                        发表栏目
                    </a>
                </li>
            </ul>
        </div>
        <div class="card-body">
            <table class="table">
                <thead>
                <tr>
                    <th>编号</th>
                    <th>栏目名称</th>
                    <th>栏目图标</th>
                    <th>父级栏目</th>
                    <th>创建时间</th>
                </tr>
                </thead>
                <tbody>
                @foreach($categories as $category)
                    <tr>
                        <td scope="row">{{$category['id']}}</td>
                        <td>{{$category['title']}}</td>
                        <td><i class="{{$category['icon']}}"></i></td>
                        <td>
                            @if($category['parent_id'] == 0)
                                顶级分类
                            @else
                                {{$category->fatherName->title}}
                            @endif
                        </td>
                        <td>{{$category['created_at']}}</td>
                        <td class="text-right">
                            <div class="btn-group btn-group-sm" role="group" aria-label="First group">
                                <a href="{{route('admin.catergory.edit',$category)}}" class="btn btn-light">修改</a>
                                <button type="button" class="btn btn-white" onclick="del({{$category['id']}})">删除</button>
                                <form action="{{route('admin.catergory.destroy',$category)}}" method="post" id="{{$category['id']}}">
                                    @csrf @method('DELETE')
                                </form>
                            </div>
                        </td>

                    </tr>
                  @endforeach
                </tbody>
            </table>
        </div>
        <div class="card-footer text-muted">
                        {{$categories->links()}}
        </div>
    </div>
@endsection
@push('js')
    <script>
        function del(id) {
            if (confirm('确定删除吗？')) {
                $('#'+id).submit();
            }
        }
    </script>
@endpush
